package com.shop.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shop.user.po.DiscountUser;
import com.shop.user.po.dto.DiscountDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author banxia
 * @since 2023-02-27
 */
public interface DiscountUserMapper extends BaseMapper<DiscountUser> {

    //订单取消对优惠券进行回填
    @Update("update discount_user set count=count+1 where user_id=#{userId} and" +
                                " discount_id=#{discountId}")
    int cancelOrderDiscountRollBack(@Param("userId") Long userId,
                                    @Param("discountId") Long discountId);

    //删除该用户discountId的优惠券
    @Update("update discount_user set count=count-1 where user_id=#{userId} and discount_id=#{discountId} " +
            "and count-1>=0")
    int deleteUserDiscount(@Param("userId") Long userId,
                           @Param("discountId") Long discountId);

    //获取用户优惠券信息
    List<DiscountDto> getDiscountDtoList(@Param("expire") Boolean expire,
                                         @Param("used") Boolean used,
                                         @Param("notStart") Boolean notStart,
                                         @Param("userId") Long userId,
                                         @Param("now") String now);
}
